﻿// search service for sending search requests to the server
angular.module('app.search').service('searchService', ['$http',
	function ($http) {
		'use strict';
		var
			// search by image id and tolerance
		byImage = function (tolerance, imageId) {
			return $http({
				url: '/api/search/image/?tolerance=' + tolerance.toString() + '&imageId=' + imageId.toString(),
				method: 'GET',
				headers: { 'Content-Type': 'application/json' }
			}).success(function (data, status, headers, config) {
			}).error(function (data, status, headers, config) {
			});
		},
		// search by pattern with tolerance and pattern id
		byPattern = function (tolerance, patternId) {
			return $http({
				url: '/api/search/pattern/?tolerance=' + tolerance.toString() + '&patternId=' + patternId.toString(),
				method: 'GET',
				headers: { 'Content-Type': 'application/json' }
			}).success(function (data, status, headers, config) {
			}).error(function (data, status, headers, config) {
			});
		},
		// search by colors
		byColors = function (colors) {
			return $http({
				url: '/api/search/color/?colors=' + colors.toString(),
				method: 'GET',
				headers: { 'Content-Type': 'application/json' }
			}).success(function (data, status, headers, config) {
			}).error(function (data, status, headers, config) {
			});
		},
		svc = {
			byImage: byImage,
			byPattern: byPattern,
			byColors: byColors
		};

		return svc;
	}]);